﻿function demonPage() {
    var self = this;

    //Inherit the CUIpage
    CUIPage.call(this);

    //initial validate pwd event
    this.pageEvent["validatePwd"] = function (e) {
        if (e.getValue() != self.demoPassword.getValue()) {
            return false;
        }
        return true;
    };
    //initial validate Pwd Strength event
    this.pageEvent["validatePwdStrength"] = function (e) {
        if (e.getValue().length > 0 && e.getValue().length < 8) {
            e.closest(".cui").addClass("cui-warning");
            $("[validate_warning='" + e.attr("id") + "']").removeClass("hide");
        }
        else {
            e.closest(".cui").removeClass("cui-warning");
            $("[validate_warning='" + e.attr("id") + "']").addClass("hide")
        }
    };
    //initial submit event
    this.pageEvent["submit"] = function () {
        if (self.demoButton.text() == "Next") {
            self.demoButton.attr("href", "/Account/Demo3");
        }
        if ($("fieldset").submitValidate()) {
            alert("success!");
            $("#otherInfo").hide().removeClass("hide").show("500");
            $("#requiredInfo").attr("disabled", "disabled").addClass("opacity-5");
            self.demoButton.text("Next");
        }
    };

    //initial error message
    this.pageEvent["error"] = function (e) {
        self.sidebarRight.show();
        var $validate_error = $("[validate_error='" + e.attr("id") + "']").closest(".section").find("h4");
        if ($validate_error.length > 0) {
            $validate_error.removeClass("text-passed");
        }
        e.closest(".cui").removeClass("cui-passed");
    };

    //initial error message
    this.pageEvent["pass"] = function (e) {
        var $validate_error = $("[validate_error='" + e.attr("id") + "']").closest(".section").find("h4");
        if ($validate_error.length > 0) {
            $validate_error.addClass("text-passed");
        }
        e.closest(".cui").addClass("cui-passed");
    };

    //initial the side bar
    this.sidebarRight = $("#rightsider").sidebar();
    this.demoEmail = $("[field='Email']").cTextbox({
        tip: "Your Email",
        attribute: {
            id: "Email",
            required: true,
            validateType: CUICore.validateType.email,
            OnValidateError: "error",
            OnValidatePass: "pass",
            CommonErrorMessage: "You must input an unique email as your account Id."
        }
    });
    this.demoPassword = $("[field='Password']").cTextbox({
        password: true,
        attribute: {
            id: "Password",
            required: true,
            minlength: 5,
            OnValidateError: "error",
            OnValidatePass: "pass",
            onItemKeyup: "validatePwdStrength",
            CommonErrorMessage: "The password cannot be empty."
        }
    });
    this.demoDPassword = $("[field='dPassword']").cTextbox({
        password: true,
        attribute: {
            id: "dPassword",
            required: true,
            validateType: "validatePwd",
            minlength: 5,
            OnValidateError: "error",
            OnValidatePass: "pass",
            ValidateErrorMessage: "The password should as same as not as same as Confirm Password!"
        }
    });
    this.demoPhone = $("[field='Phone']").cTextbox({
        tip: "Your Phone Number",
        attribute: {
            id: "Phone",
            validateType: CUICore.validateType.phone,
            OnValidateError: "error"
        }
    });

    this.demoFristName = $("[field='FristName']").cTextbox({
        tip: "Your Frist Name",
        attribute: {
            id: "FristName"
        }
    });
    this.demoTLastName = $("[field='LastName']").cTextbox({
        tip: "Your Last Name",
        attribute: {
            id: "LastName"
        }
    });
    this.demoButton = $("[field='submit']").cButton({
        attribute: {
            id: "submit",
            onItemClick: "submit"
        }
    });
}
demonPage.prototype = new CUIPage();

$(document).ready(function () {
    //inherit the CUIPage
    var currentPage = new demonPage();
    currentPage.InitialPage();
}); 
